package com.antis.olsl.main.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.antis.olsl.library.widget.MyGridView;
import com.antis.olsl.main.R;
import com.antis.olsl.main.bean.FunctionMenuInfo;
import com.antis.olsl.main.bean.HomePageMenuInfo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.adapter
 * @ClassName: A_ExampleAdapter
 * @Description: 示范类Adapter
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:58
 * @UpdateDate: 2020/3/30 19:58
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class FunctionMenuAdapter extends BaseQuickAdapter<FunctionMenuInfo, BaseViewHolder> {
    public FunctionMenuAdapter(List<FunctionMenuInfo> data) {
        super(R.layout.listitem_all_function, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final FunctionMenuInfo item) {
        helper.setText(R.id.tv_title, item.getMenuTitle());
        MyGridView gridView = helper.getView(R.id.gridView);
        final ArrayList<HomePageMenuInfo> menuInfoArrayList = item.getMenuInfos();
        FunctionMenuGridAdapter gridAdapter = new FunctionMenuGridAdapter(getContext(), menuInfoArrayList);
        gridView.setAdapter(gridAdapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                if (!TextUtils.isEmpty(menuInfoArrayList.get(position).getPath())) {
                    ARouter.getInstance()
                            .build(menuInfoArrayList.get(position).getPath())
                            .navigation();
                }
            }
        });
    }
}
